package com.lm.controller;

import com.lm.pojo.ServicePackage;
import com.lm.pojo.Tag;
import com.lm.service.ServicePackageService;
import com.lm.util.ResultUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 15833
 * @version 1.0
 * @description: TODO 服务包控制层
 * @date 2025/9/21 22:20
 */
@CrossOrigin(origins = "*")
@Api(tags = "服务包管理")
@RestController
@RequestMapping("/servicePackage")
public class ServicePackageController {

    // 注入ServicePackageService接口
    @Autowired
    private ServicePackageService servicePackageService;

    /**
     * @description: 查找所有服务包
     * @param: null
     * @return:
     * @author 15833
     * @date: 2025/9/21 22:31
     */
    @ApiOperation(value = "查找所有服务包", httpMethod = "POST", notes = "查找所有服务包")
    @PostMapping("findServicePackageList")
    public ResultUtil<List<ServicePackage>> findServicePackageList(@RequestBody ServicePackage servicePackage) {
        try {
            return new ResultUtil<>(200, "查询数据包成功", servicePackageService.findServicePackageList(servicePackage));
        } catch (Exception e) {
            e.printStackTrace();
            return new ResultUtil<>(500, "查询数据包失败");
        }
    }


    /**
     * @description: 增加服务包
     * @param: null
     * @return:
     * @author 15833
     * @date: 2025/9/22 15:58
     */
    @ApiOperation(value = "增加服务包", httpMethod = "POST", notes = "增加服务包")
    @PostMapping("addServicePackage")
    public ResultUtil<String> addServicePackage(@RequestBody ServicePackage servicePackage) {
        try {
            servicePackageService.addServicePackage(servicePackage);
            return new ResultUtil<>(200, "增加服务包成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new ResultUtil<>(500, "增加服务包失败");
        }
    }

    /**
     * @description: 修改服务包
     * @param: null
     * @return:
     * @author 15833
     * @date: 2025/9/22 17:18
     */
    @ApiOperation(value = "修改服务包", httpMethod = "PUT", notes = "修改服务包")
    @PutMapping("updateServicePackage")
    public ResultUtil<String> updateServicePackage(@RequestBody ServicePackage servicePackage) {
        try {
            servicePackageService.updateServicePackage(servicePackage);
            return new ResultUtil<>(200, "修改服务包成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new ResultUtil<>(500, "修改服务包失败");
        }
    }
    
    /**
     * @description: 根据服务包ID查询详情及其关联的服务项目
     * @param: servicePackageId 服务包ID
     * @return: 服务包详情及其关联的服务项目
     * @author 15833
     * @date: 2025/9/23 14:56
     */
    @ApiOperation(value = "查询服务包详情及其关联的服务项目", httpMethod = "GET", notes = "根据服务包ID查询详情及其关联的服务项目")
    @GetMapping("findServicePackageDetail")
    public ResultUtil<ServicePackage> findServicePackageDetail(@RequestParam Integer servicePackageId) {
        try {
            return new ResultUtil<>(200, "查询服务包详情成功", servicePackageService.findServicePackageDetail(servicePackageId));
        } catch (Exception e) {
            e.printStackTrace();
            return new ResultUtil<>(500, "查询服务包详情失败");
        }
    }
    
    /**
     * @description: 删除服务包中关联的服务项目
     * @param: servicePackageId 服务包ID
     * @param: serviceItemId 服务项目ID
     * @return: 操作结果
     * @author 15833
     * @date: 2025/9/23 15:30
     */
    @ApiOperation(value = "删除服务包中关联的服务项目", httpMethod = "DELETE", notes = "删除服务包中关联的服务项目")
    @DeleteMapping("deleteServicePackageItemRel")
    public ResultUtil<String> deleteServicePackageItemRel(@RequestParam Integer servicePackageId, @RequestParam Integer serviceItemId) {
        try {
            servicePackageService.deleteServicePackageItemRel(servicePackageId, serviceItemId);
            return new ResultUtil<>(200, "删除服务包关联服务项目成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new ResultUtil<>(500, "删除服务包关联服务项目失败");
        }
    }
    
    /**
     * @description: 添加服务包与服务项目的关联关系
     * @param: servicePackageId 服务包ID
     * @param: serviceItemId 服务项目ID
     * @return: 操作结果
     * @author 15833
     * @date: 2025/9/23 16:00
     */
    @ApiOperation(value = "添加服务包与服务项目的关联关系", httpMethod = "POST", notes = "添加服务包与服务项目的关联关系")
    @PostMapping("addServicePackageItemRel")
    public ResultUtil<String> addServicePackageItemRel(@RequestParam Integer servicePackageId, @RequestParam Integer serviceItemId) {
        try {
            servicePackageService.addServicePackageItemRel(servicePackageId, serviceItemId);
            return new ResultUtil<>(200, "添加服务包关联服务项目成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new ResultUtil<>(500, "添加服务包关联服务项目失败");
        }
    }
    
    /**
     * @description: 添加服务包与标签的关联关系
     * @param: servicePackageId 服务包ID
     * @param: tagId 标签ID
     * @return: 操作结果
     * @author 15833
     * @date: 2025/9/24 10:00
     */
    @ApiOperation(value = "添加服务包与标签的关联关系", httpMethod = "POST", notes = "添加服务包与标签的关联关系")
    @PostMapping("addServicePackageTagRel")
    public ResultUtil<String> addServicePackageTagRel(@RequestParam Integer servicePackageId, @RequestParam Integer tagId) {
        try {
            servicePackageService.addServicePackageTagRel(servicePackageId, tagId);
            return new ResultUtil<>(200, "添加服务包关联标签成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new ResultUtil<>(500, "添加服务包关联标签失败");
        }
    }

    /**
     * @description: 根据服务包ID查询其关联的完整标签信息列表
     * @param: servicePackageId 服务包ID
     * @return: 完整标签信息列表
     * @author 15833
     * @date: 2025/9/24 11:00
     */
    @ApiOperation(value = "根据服务包ID查询关联的完整标签信息列表", httpMethod = "GET", notes = "根据服务包ID查询关联的完整标签信息列表（包含标签ID和标签名称）")
    @GetMapping("findTagsByServicePackageId")
    public ResultUtil<List<Tag>> findTagsByServicePackageId(@RequestParam Integer servicePackageId) {
        try {
            List<Tag> tags = servicePackageService.findTagsByServicePackageId(servicePackageId);
            return new ResultUtil<>(200, "查询服务包关联标签成功", tags);
        } catch (Exception e) {
            e.printStackTrace();
            return new ResultUtil<>(500, "查询服务包关联标签失败");
        }
    }

    /**
     * @description: 删除服务包与标签的关联关系
     * @param: servicePackageId 服务包ID
     * @param: tagId 标签ID
     * @return: 操作结果
     * @author 15833
     * @date: 2025/9/24 12:00
     */
    @ApiOperation(value = "删除服务包与标签的关联关系", httpMethod = "DELETE", notes = "删除服务包与标签的关联关系")
    @DeleteMapping("deleteServicePackageTagRel")
    public ResultUtil<String> deleteServicePackageTagRel(@RequestParam Integer servicePackageId, @RequestParam Integer tagId) {
        try {
            servicePackageService.deleteServicePackageTagRel(servicePackageId, tagId);
            return new ResultUtil<>(200, "删除服务包关联标签成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new ResultUtil<>(500, "删除服务包关联标签失败");
        }
    }
}
